﻿<%@ page language="java" contentType="text/html; charset=UTF-8"
         pageEncoding="UTF-8" %>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<%@ taglib prefix="fmt" uri="http://java.sun.com/jsp/jstl/fmt" %>
<%@ page isELIgnored="false" %>
<%
    String path = request.getContextPath();
%>
<!DOCTYPE html>
<html>
<head>

    <meta charset="utf-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">


    <title>李宁体育管理系统</title>

    <link rel="shortcut icon" href="favicon.ico">
    <link href="<%=path%>/css/bootstrap.min14ed.css?v=3.3.6" rel="stylesheet">
    <link href="<%=path%>/css/font-awesome.min93e3.css?v=4.4.0" rel="stylesheet">
    <link href="<%=path%>/css/plugins/bootstrap-table/bootstrap-table.min.css" rel="stylesheet">
    <link href="<%=path%>/css/style.min862f.css?v=4.1.0" rel="stylesheet">
    <link href="<%=path%>/css/plugins/chosen/chosen.css" rel="stylesheet">

    <link href="<%=path%>/css/plugins/ionRangeSlider/ion.rangeSlider.css" rel="stylesheet">
    <link href="<%=path%>/css/plugins/ionRangeSlider/ion.rangeSlider.skinFlat.css" rel="stylesheet">
    <link href="<%=path%>/css/plugins/awesome-bootstrap-checkbox/awesome-bootstrap-checkbox.css"
          rel="stylesheet">
    <link href="<%=path%>/css/animate.min.css" rel="stylesheet">
    <link href="<%=path%>/css/style.min862f.css?v=4.1.0" rel="stylesheet">

</head>

<body class="gray-bg">
<div class="wrapper wrapper-content animated fadeInRight">
    <div class="row">
        <div class="col-sm-12">
            <div class="ibox float-e-margins">
                <div class="ibox-content">
                    <form class="form-horizontal m-t" id="signupForm"">
                        <div class="form-group">
                            <label class="col-sm-2 control-label">用户名：</label>

                            <div class="col-sm-4">
                                <input id="USERNAME" name="USERNAME" class="form-control" type="text" value="" maxlength="15" placeholder="这里输入用户名">
                            </div>
                            <span id="error_USERNAME" style="color: red">*</span>
                        </div>
                       
                        <div class="form-group">
                            <label class="col-sm-2 control-label">密码：</label>

                            <div class="col-sm-4">
                                <input id="PASSWORD" name="PASSWORD" class="form-control" type="password"  maxlength="32" placeholder="输入密码">
                            </div>
                             <span id="error_PASSWORD" style="color: red">*</span>
                        </div>
                 

                        <div class="form-group">
                            <label class="col-sm-2 control-label">手机号：</label>

                            <div class="col-sm-4">
                                <input id="PHONE" name="PHONE" class="form-control" type="number" value=""   maxlength="11" placeholder="这里输入手机号" >
                            </div>
                            <span id="error_PHONE" style="color: red">*</span>
                        </div>

                        <div class="form-group">
                            <label class="col-sm-2 control-label">邮箱：</label>

                            <div class="col-sm-4">
                                <input id="EMAIL" name="EMAIL" class="form-control" type="email" value=""  maxlength="64" placeholder="这里输入邮箱">
                            </div>
                            <span id="error_EMAIL" style="color: red">*</span>
                        </div>
                        <div class="form-group">
                            <label class="col-sm-2 control-label">品牌：</label>

                            <div class="col-sm-4">
                                   <select class="chosen-select form-control" name="ROLE_ID" id="ROLE_ID" data-placeholder="请选择品牌" >
                                <option value=""></option>
                                <c:forEach items="${list }" var="mp">
                                    <option value="${mp.id }" selected>${mp.nickName }</option>
                                </c:forEach>
                            </select>
                            </div>
                             <span id="error_ROLE_ID" style="color: red">*</span>
                        </div>
                        <div class="form-group">
                            <div class="col-sm-4 col-sm-offset-3">
                                <button class="btn btn-primary" type="submit">提交</button>
                               <!--  &nbsp;<button class="btn btn-success" type="reset">重置</button> -->
                                &nbsp;<button class="btn btn-info" type="button" onclick="goback()">返回</button>
                            </div>
                        </div>
                    </form>
                </div>
            </div>
        </div>
    </div>
</div>
<script src="<%=path%>/js/jquery.min.js?v=2.1.4"></script>
<script src="<%=path%>/js/bootstrap.min.js"></script>
<script src="<%=path%>/js/jquery.validate.js"></script>
<script src="<%=path%>/js/jquery.serializeObject.js"></script>
<!--下拉框-->
<script src="<%=path%>/js/plugins/chosen/chosen.jquery.js"></script>

<script>
var config = {
        ".chosen-select": {},
        ".chosen-select-deselect": {allow_single_deselect: !0},
        ".chosen-select-no-single": {disable_search_threshold: 10},
        ".chosen-select-no-results": {no_results_text: "Oops, nothing found!"},
        ".chosen-select-width": {width: "95%"}
    };
for (var selector in config)$(selector).chosen(config[selector]);
$(document).ready(function () {
	var flage=true;
	$("#signupForm").validate({
		rules: {
			USERNAME: {
				required: true,
			},
			PASSWORD: {
				required: true,
			},
			PHONE: {
				required: true,
				rangelength:[11,11]
			},
			EMAIL: {
				required: true,
				email:true,
			},
			ROLE_ID: {
				required: true,
			}

		},
		messages:{
			USERNAME:{
				required: "用户名不能为空"
			},
			PASSWORD:{
				required: "密码不能为空"
			},
			PHONE:{
				required: "电话号码不符合规则"
			},
			EMAIL:{
				required: "邮箱不符合规则"
			},
			ROLE_ID:{
				required: "门店不能为空"
			},
		
		},
		errorPlacement: function(error, element) {
			$( element ).closest( "form" ).find( "span[id='error_" + element.attr( "name" ) + "']" ).append( error );
		},
	    onkeyup: false,
		submitHandler:function(){	
			var roleForm = $("#signupForm").serializeObject();
			if(flage){
			jQuery.ajax({
				type: "post",
			    url: "<%=path%>/manager/toAddAccount",
			    contentType: "application/json",
			    data: JSON.stringify(roleForm),
			    beforeSend:function() {
			    	$("#progress").modal();
			    	$("#loading").html("正在提交用戶数据，请稍候...");

			    },
			    complete:function(data) {
			    	$("#progress").modal('hide');
			    	$("#loading").html("");
			    }, 
			    success: function (data) {
			    	if(data.status==200){
			    		parent.layer.msg("保存数据信息成功!",{time: 500},function(){goback();});
			    	}else{
			    		parent.layer.msg("保存数据信息失败!");			    		
			    	}
			    },
			    error: function () {
			    	parent.layer.msg("保存数据信息失败,请联系管理员!");
			    }	
			});
			}else{
				$("#error_USERNAME").html("用户名重复无法提交");
			}
		}
	});
    $("#USERNAME").blur(function(){
    	var userName=$("#USERNAME").val();
    	$("#error_USERNAME").html("");
    	if(userName){
    		jQuery.ajax({
				type: "post",
			    url: "<%=path%>/user/toCheckUserName",
			    dateType: "json",
			    data: {"userName":userName},
			    success: function (data) {
			    	if(data.status==400){
			    		$("#error_USERNAME").html(data.msg);
			    		flage=false;
			    	}else{
			    		$("#error_USERNAME").html("");
			    		flage=true;
			    	}
			    },
			});	
    	}
    });
});
    
    
    function goback() {
		/* parent.window.location.reload();
		var index = parent.layer.getFrameIndex(window.name); //获取窗口索引
		parent.layer.close(index); */
    	window.location.href="<%=path%>/manager/listAccount";
	}
</script>
</body>
</html>
